<?php


namespace App\Transformers\Store;


use App\Models\LiveAnchor;
use App\Models\Product;
use App\Models\ShippingTemplates;
use App\Models\StoreSeckill;
use App\Transformers\Product\ProductAttrTransformer;
use App\Transformers\Product\ProductTransformer;
use App\Transformers\Shipping\ShippingTemplatesTransformer;
use League\Fractal\TransformerAbstract;

class StoreSeckillTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['product'];

    public function transform(StoreSeckill $data)
    {
        return [
            'id' => $data->id,
            'product_id' => $data->product_id ?? "",
            'recommend_image' => $data->recommend_image ?? "",
            'recommend_image_url' => $data->recommend_image ?? 'https://placeimg.com/640/480/any',
            'rotation_chart' => $data->rotation_chart ?? "",
            'rotation_chart_url' => $data->rotation_chart ?? 'https://placeimg.com/640/480/any',
            'title' => $data->title ?? "",
            'introduction' => $data->introduction ?? "",
            'price' => $data->price ?? "",
            'cost' => $data->cost ?? "",
            'original_price' => $data->original_price ?? "",
            'give_integral' => $data->give_integral ?? "",
            'sort' => $data->sort ?? "",
            'stock' => $data->stock ?? "",
            'sales' => $data->sales ?? "",
            'unit_name' => $data->unit_name ?? "",
            'postage' => $data->postage ?? "",
            'description' => $data->description ?? "",
            'start_time' => $data->start_time ?? "",
            'stop_time' => $data->stop_time ?? "",
            'num' => $data->num ?? "",
            'time_id' => $data->time_id ?? "",
            'once_num' => $data->once_num ?? "",
            'temp_id' => $data->temp_id ?? "",
            'weight' => $data->weight ?? "",
            'volume' => $data->volume ?? "",
            'quota' => $data->quota ?? "",
            'is_show' => $data->is_show ?? 0,
            'quota_show' => $data->quota_show ?? 0,
            'atr_status' => $data->atr_status ?? 0,
            'status' => $data->statusEnum[$data->status] ?? '',
            'is_postage' => $data->is_postage ?? 0,
            'is_hot' => $data->is_hot ?? 0,
            'deleted_at' => $data->deleted_at ? $data->deleted_at->format("Y-m-d H:i:s") : '',
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
            'att_r' => $data->att_r ?? '',
        ];
    }

    /**
     *额外包含商品数据
     */

    public function includeProduct(StoreSeckill $storeSeckill)
    {
        return $this->item($storeSeckill->product, new ProductTransformer());
    }



}
